package com.ffapp.demo.bean;

import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.model.LatLng;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.services.core.LatLonPoint;
import com.ffapp.demo.R;
import com.ffapp.demo.map.GPSUtil;

import java.util.ArrayList;

public class WarnInfoData extends BasisBean {


    String alarmType = "未登记";                   //1 警情   2隐患    3救援
    private String source;
    private String matchLongitude;
    private String calamityType;
    private String updateBy;
    private String status;
    private String id;
    private String incidentLongitude;
    private int version;
    private String alarmTime;
    private String createBy;
    private String incidentLatitude;
    private String no = "未登记";
    private String longitude;
    private String matchLatitude;
    private String endTime;
    private String createUserName;
    private String managementDeptId;
    private String incidentAddress = "未登记";
    private String incidentDescription = "";
    private String managementDeptName  = "未登记";
    private String areaName;
    private String updateTime;
    private String alarmUserPhone = "未登记";
    private String createTime;
    private String latitude;
    private String updateUserName;
    private String areaNo;
    private String alarmLatitude;

    private String coordinate = "未登记";


    private String alarmAddress;

    private ArrayList<ProjectFileData> files = new ArrayList<>();

    public String getAlarmUserName() {
        if(TextUtils.isEmpty(alarmUserName))return "未登记";
        return alarmUserName;
    }

    public void setAlarmUserName(String alarmUserName) {
        this.alarmUserName = alarmUserName;
    }

    private String alarmUserName;

    public String getAlarmLongitude() {
        return alarmLongitude;
    }

    public void setAlarmLongitude(String alarmLongitude) {
        this.alarmLongitude = alarmLongitude;
    }

    private String alarmLongitude;


    public String getAlarmType() {
        return alarmType;
    }

    public void setAlarmType(String alarmType) {
        this.alarmType = alarmType;
    }

    public String getAlarmTypeName() {
        return alarmType;
    }

    public int getAlarmTypeIcon() {
        int icon = R.drawable.list_icon_hzjq;
        //1 警情   2隐患    3救援
        switch (alarmType) {
            case "火灾":
                icon = R.drawable.list_icon_hzjq;
                break;
            case "抢险救援":
                icon = R.drawable.list_icon_qxjy;
                break;
            case "社会救助":
                icon = R.drawable.list_icon_shjy;
                break;
        }
        return icon;
    }


    public int getAlarmTypeColor() {
        int color = R.color.warn_yellow;
        //1 警情   2隐患    3救援
        switch (alarmType) {
            case "火灾":
                color = R.color.warn_yellow;
                break;
            case "抢险救援":
                color = R.color.warn_blue;
                break;
            case "社会救助":
                color = R.color.warn_green;
                break;
            case "灾害事故":
                color = R.color.warn_violet;
                break;
            case "防恐排爆":
                color = R.color.warn_pink;
                break;
        }
        return color;
    }

    public int getAlarmBackgroundColor() {
        int color = R.color.warn_half_yellow;
        //1 警情   2隐患    3救援
        switch (alarmType) {
            case "火灾":
                color = R.color.warn_half_yellow;
                break;
            case "抢险救援":
                color = R.color.warn_half_blue;
                break;
            case "社会救助":
                color = R.color.warn_half_green;
                break;
            case "灾害事故":
                color = R.color.warn_half_violet;
                break;
            case "防恐排爆":
                color = R.color.warn_half_pink;
                break;
        }
        return color;
    }

    public LatLng getLatlng() {
        if (TextUtils.isEmpty(latitude) || TextUtils.isEmpty(latitude)) {
            return new LatLng(0, 0);
        }

        double[] gprs = GPSUtil.gps84_To_Gcj02(Double.valueOf(latitude),Double.valueOf(longitude));
        LatLng latLng = new LatLng(gprs[0], gprs[1]);
        return latLng;
    }

    public LatLng getIncidentLatlng() {
        if (TextUtils.isEmpty(incidentLongitude) || TextUtils.isEmpty(incidentLatitude)) {
            return new LatLng(0, 0);
        }

        double[] gprs = GPSUtil.gps84_To_Gcj02(Double.valueOf(incidentLatitude),Double.valueOf(incidentLongitude));
        LatLng latLng = new LatLng(gprs[0], gprs[1]);
        return latLng;
    }
    public LatLng getMatchLatlng() {
        if (TextUtils.isEmpty(matchLongitude) || TextUtils.isEmpty(matchLatitude)) {
            return new LatLng(0, 0);
        }

        double[] gprs = GPSUtil.gps84_To_Gcj02(Double.valueOf(matchLatitude),Double.valueOf(matchLongitude));
        LatLng latLng = new LatLng(gprs[0], gprs[1]);
        return latLng;
    }

    public String getLatlngType() {
        if (TextUtils.isEmpty(latitude) || TextUtils.isEmpty(longitude)) {
            return null;
        }
        if (TextUtils.isEmpty(incidentLongitude) && TextUtils.isEmpty(matchLongitude)) {
            return "match" ;
        }

        float incidentDistance = -1;
        if(!TextUtils.isEmpty(incidentLongitude) && !TextUtils.isEmpty(incidentLatitude)){
            incidentDistance = AMapUtils.calculateLineDistance(getLatlng(), getIncidentLatlng());
        }

        float matchDistance = -1;
        if(!TextUtils.isEmpty(matchLongitude) && !TextUtils.isEmpty(matchLatitude)){
            matchDistance = AMapUtils.calculateLineDistance(getLatlng(), getMatchLatlng());
        }

        if(incidentDistance != -1 && matchDistance != -1){
            if(incidentDistance < matchDistance){
                return "warn" ;
            }else {
                return "match" ;
            }

        }else if(incidentDistance == -1 && matchDistance != -1){
            return "match" ;
        }else if(incidentDistance != -1 && matchDistance == -1){
            return "warn" ;
        }
        return null;
    }

    public void setLatlng(String latitude,String longitude) {
        if (TextUtils.isEmpty(latitude) || TextUtils.isEmpty(longitude)) {
            return;
        }
        double[] gprs = GPSUtil.gcj02_To_Gps84(Double.valueOf(latitude),Double.valueOf(longitude));
        this.latitude = String.valueOf(gprs[0]);
        this.longitude = String.valueOf(gprs[1]);
    }

    public NaviLatLng getNaviLatLng() {
        if (TextUtils.isEmpty(latitude) || TextUtils.isEmpty(latitude)) {
            return null;
        }

        double[] gprs = GPSUtil.gps84_To_Gcj02(Double.valueOf(latitude),Double.valueOf(longitude));

        NaviLatLng latLng = new NaviLatLng(gprs[0], gprs[1]);
        return latLng;
    }

    public LatLonPoint getLatLonPoint() {
        if (TextUtils.isEmpty(latitude) || TextUtils.isEmpty(latitude)) {
            return new LatLonPoint(0, 0);
        }

        double[] gprs = GPSUtil.gps84_To_Gcj02(Double.valueOf(latitude),Double.valueOf(longitude));

        LatLonPoint latLng = new LatLonPoint(gprs[0], gprs[1]);
        return latLng;
    }



    public String getSource() {
        return source;
    }

    public String getSourceName() {
        switch (source){
            case "10":
                return "119报警";
            case "20":
                return "110报警";
            case "30":
                return "物联网报警";
            case "40":
                return "微信报警";
        }
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getMatchLongitude() {
        return matchLongitude;
    }

    public void setMatchLongitude(String matchLongitude) {
        this.matchLongitude = matchLongitude;
    }

    public String getCalamityType() {
        return calamityType;
    }

    public void setCalamityType(String calamityType) {
        this.calamityType = calamityType;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIncidentLongitude() {
        return incidentLongitude;
    }

    public void setIncidentLongitude(String incidentLongitude) {
        this.incidentLongitude = incidentLongitude;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getAlarmTime() {
        return alarmTime;
    }

    public void setAlarmTime(String alarmTime) {
        this.alarmTime = alarmTime;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getIncidentLatitude() {
        return incidentLatitude;
    }

    public void setIncidentLatitude(String incidentLatitude) {
        this.incidentLatitude = incidentLatitude;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getMatchLatitude() {
        return matchLatitude;
    }

    public void setMatchLatitude(String matchLatitude) {
        this.matchLatitude = matchLatitude;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getCreateUserName() {
        return createUserName;
    }

    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }

    public String getManagementDeptId() {
        return managementDeptId;
    }

    public void setManagementDeptId(String managementDeptId) {
        this.managementDeptId = managementDeptId;
    }

    public String getIncidentAddress() {
        return incidentAddress;
    }

    public void setIncidentAddress(String incidentAddress) {
        this.incidentAddress = incidentAddress;
    }

    public String getManagementDeptName() {
        return managementDeptName;
    }

    public void setManagementDeptName(String managementDeptName) {
        this.managementDeptName = managementDeptName;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getAlarmUserPhone() {
        if(alarmUserPhone.equals("-")){
            return "未登记";
        }
        return alarmUserPhone;
    }

    public void setAlarmUserPhone(String alarmUserPhone) {
        this.alarmUserPhone = alarmUserPhone;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getUpdateUserName() {
        return updateUserName;
    }

    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }

    public String getAreaNo() {
        return areaNo;
    }

    public void setAreaNo(String areaNo) {
        this.areaNo = areaNo;
    }

    public String getAlarmLatitude() {
        return alarmLatitude;
    }

    public void setAlarmLatitude(String alarmLatitude) {
        this.alarmLatitude = alarmLatitude;
    }



    private String phone;
    private int outState;
    private String filePath;
    private int type;
    private String address;
    private String fileName;
    private String name;
    private String deleted;
    private String addLocal;
    private int distance;
    private int radiantRadius;
    private String auditStatus;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getOutState() {
        return outState;
    }

    public void setOutState(int outState) {
        this.outState = outState;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDeleted() {
        return deleted;
    }

    public void setDeleted(String deleted) {
        this.deleted = deleted;
    }

    public String getAddLocal() {
        return addLocal;
    }

    public void setAddLocal(String addLocal) {
        this.addLocal = addLocal;
    }

    public int getDistance() {
        return distance;
    }

    public void setDistance(int distance) {
        this.distance = distance;
    }

    public int getRadiantRadius() {
        return radiantRadius;
    }

    public void setRadiantRadius(int radiantRadius) {
        this.radiantRadius = radiantRadius;
    }

    public String getAuditStatus() {
        return auditStatus;
    }

    public void setAuditStatus(String auditStatus) {
        this.auditStatus = auditStatus;
    }

    public String getPreviewPath() {
        return previewPath;
    }

    public void setPreviewPath(String previewPath) {
        this.previewPath = previewPath;
    }

    private String previewPath;

    public String getAlarmAddress() {
        return alarmAddress;
    }

    public void setAlarmAddress(String alarmAddress) {
        this.alarmAddress = alarmAddress;
    }

    @JSONField(serialize = false)
    public String getGaodeUrl(){
        LatLng latLng = getLatlng();
        StringBuilder builder = new StringBuilder();
        builder.append("https://uri.amap.com/marker?position="+latLng.longitude+","+latLng.latitude).append("&name=")
                .append(getIncidentAddress())
        ;
        return builder.toString();

    }

    @JSONField(serialize = false)
    public String getShareStr(){
        StringBuilder builder = new StringBuilder();
        builder.append(LoginBean.getInstance().getUserInfo().getName()).append("分享了一个警情位置:").append(getIncidentAddress()).append("--").append(getGaodeUrl());
        return builder.toString();
    }

    public String getCoordinate() {
        if(TextUtils.isEmpty(longitude) || TextUtils.isEmpty(latitude)){
            return coordinate;
        }else {
            if(longitude.length() > 10){
                longitude = longitude.substring(0,10);
            }
            if(latitude.length()> 9){
                latitude = latitude.substring(0,9);
            }
            return ""+getLongitude()+","+getLatitude();
        }
    }

    public String getIncidentDescription() {
        if(TextUtils.isEmpty(incidentDescription))return "未登记";
        return incidentDescription;
//        String a = incidentDescription;
//        return a.replaceAll("死亡","**").replaceAll("死","*").replaceAll("牺牲","**");
    }

    public void setIncidentDescription(String incidentDescription) {
        this.incidentDescription = incidentDescription;
    }

    public void setCoordinate(String coordinate) {
        this.coordinate = coordinate;
    }

    public ArrayList<ProjectFileData> getFiles() {
        return files;
    }

    public void setFiles(ArrayList<ProjectFileData> files) {
        this.files = files;
    }
}
